<template>
  <dt-modal-edit
    ref="modal"
    title="发票回执上传"
    :label-width="90"
    :width="450"
    @ok="onOk"
    :loading="loading" />
</template>

<script>
  import Opt from '../opt/InvoiceReceiptOpt.js'
  import settlementMgr from '@/biz/commission/settlement.js'

  export default {
    data() {
      return {
        loading: false,
        info: {}
      }
    },
    methods: {
      show(info) {
        this.info = {
          isInvoiceDelayUpload: false,
          delayTime: 'ONE',
          invoiceReceiptAttaches: null,
          ...info
        }
        this.$refs.modal.show(new Opt(this.info), this.info)
      },
      hide() {
        this.$refs.modal.hide()
      },
      onOk() {
        this.loading = true
        settlementMgr
          .editSettlement({
            commissionId: this.info.commissionId,
            isInvoiceDelayUpload: this.info.isInvoiceDelayUpload ?? false,
            delayTime: this.info.delayTime,
            invoiceReceiptAttaches: this.info.invoiceReceiptAttaches
          })
          .then(() => {
            this.loading = false
            this.$Message.success('确认成功')
            this.$emit('success')
            this.hide()
          })
          .catch(() => {
            this.loading = false
          })
      }
    }
  }
</script>

<style></style>
